﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using StoreHoursDomain.Entity;
using Domain.Provider;
using Domain;
using Ninject;
using Domain.ActiveDirectory.Provider;
using StoreHoursDomain.Provider;

namespace WebUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel _kernel;

        public NinjectControllerFactory()
        {
            _kernel = new StandardKernel();

            ApplyBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)_kernel.Get(controllerType);
        }

        public void ApplyBindings()
        {
            _kernel.Bind<IActiveDirectoryDataProvider>().To<ActiveDirectoryDataProvider>().InSingletonScope();
            _kernel.Rebind<IDataProvider<Store>>().To<StoreProvider>();
        }
    }
}